#! /bin/sh

dirRoot="${1}"

if [ ! -f "${dirRoot}/_aux/commit-id" ] ; then
	echo "dirRoot not set!"
	exit 1
fi

shift

commitId="${1}"

if [ -z "${commitId}" ] ; then
	echo "commitId path not set!"
	exit 1
fi

shift

newCommitId="$(mktemp "${commitId}.XXXXXXXXXX")"

echo "#define COMMIT_ID \"$(${dirRoot}/_aux/commit-id)\"" > "${newCommitId}"

if ! diff -q "${newCommitId}" "${commitId}" > /dev/null 2>&1 ; then
	mv "${newCommitId}" "${commitId}"
else
	/bin/rm "${newCommitId}"
fi

